package com.deeper.customview.ui.c1.demo;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.deeper.customview.BaseFragment;
import com.deeper.customview.R;

public class Chapter01Demo02Fragment extends BaseFragment {

    private ImageView iv;


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_chapter01_demo02, container, false);

        iv = root.findViewById(R.id.iv);

        Bitmap bmpBuffer = Bitmap.createBitmap(500, 800, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bmpBuffer);

        Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
        //原大小绘制
        canvas.drawBitmap(bitmap, 0, 0, null);
        //缩放绘制
        int bitmapWidth = bitmap.getWidth();
        int bitmapHeight = bitmap.getHeight();
        Rect src = new Rect(0, 0, bitmapWidth, bitmapHeight);
        Rect dst = new Rect(0, bitmapHeight, bitmapWidth * 3, bitmapHeight * 3 + bitmapHeight);
        canvas.drawBitmap(bitmap, src, dst, null);

        iv.setImageBitmap(bmpBuffer);
        return root;
    }
}
